<?php
class podcms_shop_product extends EDO_object_basic
{
	static $_tables = array('podcms_shop_products');
	
	static $_relations = array
	(
		array(
		'name' => 'category',
		'type' => 'relation_belongs_to',
		'class_name' => 'podcms_shop_category',
		'foreign_key' => 'categoryid',
		'render_as' => 'dropdown',
		'display' => '%name',
		'order' => 'name ASC',
		),
	
		array(
		'name' => 'developer',
		'type' => 'relation_belongs_to',
		'foreign_key' => 'developerid',
		'class_name' => 'podcms_shop_company',
		'render_as' => 'dropdown',
		'display' => '%name',
		'order' => 'name ASC',
		),

		array(
		'name' => 'publisher',
		'type' => 'relation_belongs_to',
		'foreign_key' => 'publisherid',
		'class_name' => 'podcms_shop_company',
		'display' => '%name',
		'render_as' => 'dropdown',
		'order' => 'name ASC',
		),
		
		array(
		'name' => 'genres',
		'type' => 'relation_has_and_belongs_to_many',
		'class_name' => 'podcms_shop_genre',
		'foreign_key' => 'products',
		'display' => '%name',
		'render_as' => 'select',
		'order' => 'name ASC',
		)

		
	);
	
	
	
	
	public function delete()
	{
		parent::delete();
		$phrase = "DELETE FROM relation_podcms_shop_product_genre_podcms_shop_genre WHERE sourceid = {$this->getField('edoid')}";
		$this->ldb->exec($phrase);
	}

	
	
	public function alterToStore($quantity)
	{
		$this->in_store = ($this->in_store + $quantity);
		
		$transactionid = $this->ldb->nextId('transactionid');
		
		$now = time();
		
		$phrase = "INSERT INTO podcms_shop_transactions VALUES ({$transactionid}, {$this->edoid}, {$quantity}, {$now})";

		$this->ldb->exec($phrase);
		
		
	}
	
	
}

	
	
	
	
	
	
	
	
	
	
